package org.foreveross.hbase.client;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
import org.apache.log4j.Logger;

import com.fare.taluo.vo.core.AgentEntityVO;
import com.fare.taluo.vo.core.AgentInfo;
import com.fare.taluo.vo.core.HomeChannelCompare;
import com.fare.taluo.vo.core.PlaneInfo;
import com.fare.taluo.vo.taobaoPriceRubik.TaobaoPriceRubikVO;

public class HBasePlaneinfoHelper {
	
	
	private static Logger log = Logger.getLogger("hbase");
	private static Map<String,Method> planeInfoMethods = new HashMap<String, Method>();
	private static Map<String,Method> agentMethods = new HashMap<String, Method>(); 
	private static Map<String,Method> agentMethodss = new HashMap<String, Method>();

	static{
		Method[] planeInfoMs = PlaneInfo.class.getMethods();
		Class<?>[] clazz = null;
		Class<?> clz = null;
		for (Method m : planeInfoMs) {
			clazz = m.getParameterTypes();
			if(m.getName().startsWith("set") && clazz != null && clazz.length == 1){
				clz = clazz[0];
				if(!Collection.class.isAssignableFrom(clz)) //非设置集合的
					planeInfoMethods.put(m.getName(), m);
			}
		}
		Method[] agentMs = AgentInfo.class.getMethods();
		for (Method m : agentMs) {
			clazz = m.getParameterTypes();
			if(m.getName().startsWith("set") && clazz != null && clazz.length == 1){
				clz = clazz[0];
				if(!Collection.class.isAssignableFrom(clz)) //非设置集合的
					agentMethods.put(m.getName(), m);
			}
		}
		Method[] agentMss = AgentEntityVO.class.getMethods();
		for (Method m : agentMss) {
			clazz = m.getParameterTypes();
			if(m.getName().startsWith("set") && clazz != null && clazz.length == 1){
				clz = clazz[0];
				if(!Collection.class.isAssignableFrom(clz)) //非设置集合的
					agentMethodss.put(m.getName(), m);
			}
		}
	}
	// 测试 南航 预警发送邮件是否生效
	public static List<PlaneInfo> testSendEmail(ResultScanner scan) {
		List<PlaneInfo> list = new ArrayList<PlaneInfo>();
		PlaneInfo plane = new PlaneInfo();
		plane.setAreaCode("07");
		plane.setAreaName("华南");
		plane.setCarrierFullName("中国海南航空公司");
		plane.setCarrierKey("HU");
		plane.setCarrierName("中国海南航空公司");
		plane.setFlightBatchDate("2013-03-12");
		plane.setFlightBatchStartTime("20130312084000");
		plane.setFlightBatchEndTime("20130313130000");
		plane.setFlightId("HU7804");
		plane.setFromCity("CAN");
		plane.setFromCityName("广州");
		plane.setGrabChannel("00001");
		plane.setGrabChannelNum("00001");
		plane.setGrabDate("20130311090501529");
		plane.setHighPrice("1111111");
		plane.setLowerPrice("100");
		plane.setToCity("PEK");
		plane.setToCityName("北京(PEK)");
		list.add(plane);

		PlaneInfo plane1 = new PlaneInfo();
		plane1.setAreaCode("07");
		plane1.setAreaName("华南");
		plane1.setCarrierFullName("中国南航航空公司");
		plane1.setCarrierKey("CZ");
		plane1.setCarrierName("中国南航航空公司");
		plane1.setFlightBatchDate("2013-03-13");
		plane1.setFlightBatchStartTime("20130313190000");
		plane1.setFlightBatchEndTime("20130314222000");
		plane1.setFlightId("CZ3105");
		plane1.setFromCity("CAN");
		plane1.setFromCityName("广州");
		plane1.setGrabChannel("00001");
		plane1.setGrabChannelNum("00001");
		plane1.setGrabDate("20130312040500994");
		plane1.setHighPrice("1528");
		plane1.setLowerPrice("123");
		plane1.setToCity("PEK");
		plane1.setToCityName("北京(PEK)");
		list.add(plane1);
		return list;
	}

	public static void main(String[] args) throws IllegalAccessException,
			IllegalArgumentException, Exception,
			NoSuchMethodException, SecurityException {
		//planeinfo  agentInfos
		List<Filter> filterList = new ArrayList<Filter>();
		SingleColumnValueFilter singleFilter = new SingleColumnValueFilter("agentInfos".getBytes(), "type".getBytes(), CompareOp.EQUAL, "0".getBytes());//过滤得到【直营店】type=0
		 filterList.add(singleFilter);
		String startRowKey="00001000000000000002013051613";
	 	String endRowKey  ="00001ZZZZZZ00ZZZZZZ2013051613";
	 	ResultScanner rs = HBaseHelper.getRecords("LP_FLIGHT", startRowKey,	endRowKey,null,null);
			List<PlaneInfo> res = HBasePlaneinfoHelper.transformHBaseResultToPlaneinfo(rs);
			for (PlaneInfo planeInfo : res) {
				System.out.println("planeInfo:"+planeInfo.getCarrierName());
				List<AgentInfo> ags = planeInfo.getAgentInfos();
				if(ags != null){
					for (AgentInfo agentInfo : ags) {
						System.out.println("agentInfo:"+agentInfo.getName());
					}
				}
			}
	}
	public static List<PlaneInfo> transformHBaseResultToPlaneinfo(Result[] rs){
		long start = System.currentTimeMillis();
		List<PlaneInfo> result = new ArrayList<PlaneInfo>();
		String qualifier,value,family;
		String[] agentInfoKey;
		for (Result r : rs) {
			List<AgentInfo> agents = new ArrayList<AgentInfo>();
			Map<String,AgentInfo> agentMap = new HashMap<String, AgentInfo>();
			PlaneInfo planeInfo = new PlaneInfo();
			try {
				for (KeyValue kv : r.raw()) {
					qualifier = new String(kv.getQualifier(),"utf-8");
					family = new String(kv.getFamily(),"utf-8");
					value = new String(kv.getValue(), "utf-8");
					if ("planeinfo".equals(family)) {
						Method method = planeInfoMethods.get("set" + qualifier.substring(0, 1).toUpperCase()+ qualifier.substring(1));
						if(null != method){
							method.invoke(planeInfo, value);
						}
					}else if ("agentInfos".equals(family)) {
						agentInfoKey = new String(kv.getQualifier(),"utf-8").split("_");
						String property = agentInfoKey[0];
						String str = agentInfoKey[1];
						Method method = agentMethods.get("set"+ property.substring(0, 1)
								.toUpperCase()+ property.substring(1));
						if (null != method) {
							if (!agentMap.containsKey(str)) {
								agentMap.put(str, new AgentInfo());
							}
							if (agentMap.keySet().contains(str)) 
								method.invoke(agentMap.get(str),new String(kv.getValue(), "utf-8"));
						}
					}
				}
				agents.addAll(agentMap.values());
				planeInfo.setAgentInfos(agents);
				result.add(planeInfo);
			} catch (Exception e) {
				try {
					log.error("Row--->"+new String(r.getRow(), "utf-8"), e);
				} catch (UnsupportedEncodingException e1) {
					e1.printStackTrace();
				}
			}
		}
		log.debug(" 将Result[]转化为planeinfo对象，共用时(ms)："+(System.currentTimeMillis()-start)   +"    转化对象数量："+result.size());
		return result;
	}
	public static List<PlaneInfo> transformHBaseResultToPlaneinfo(
			ResultScanner scan)  {
		long start = System.currentTimeMillis();
		List<PlaneInfo> result = new ArrayList<PlaneInfo>();
		String qualifier,value,family;
		String[] agentInfoKey;
		for (Result r : scan) {
			List<AgentInfo> agents = new ArrayList<AgentInfo>();
			Map<String,AgentInfo> agentMap = new HashMap<String, AgentInfo>();
			PlaneInfo planeInfo = new PlaneInfo();
			try {
				for (KeyValue kv : r.raw()) {
					qualifier = new String(kv.getQualifier(),"utf-8");
					family = new String(kv.getFamily(),"utf-8");
					value = new String(kv.getValue(), "utf-8");
					if ("planeinfo".equals(family)) {
						Method method = planeInfoMethods.get("set" + qualifier.substring(0, 1).toUpperCase()+ qualifier.substring(1));
						if(null != method){
							if("setFreightType".equals(method.getName())){//暂时写死，到时请修改
								int freightType=Integer.parseInt(value);
								method.invoke(planeInfo, freightType);
							}else{
								method.invoke(planeInfo, value);
							}
							
						}
					}else if ("agentInfos".equals(family)) {
						agentInfoKey = new String(kv.getQualifier(),"utf-8").split("_");
						String property = agentInfoKey[0];
						String str = agentInfoKey[1];
						Method method = agentMethods.get("set"+ property.substring(0, 1)
								.toUpperCase()+ property.substring(1));
						if (null != method) {
							if (!agentMap.containsKey(str)) {
								agentMap.put(str, new AgentInfo());
							}
							if (agentMap.keySet().contains(str)) 
								method.invoke(agentMap.get(str),new String(kv.getValue(), "utf-8"));
						}
					}
				}
				agents.addAll(agentMap.values());
				planeInfo.setAgentInfos(agents);
				result.add(planeInfo);
			} catch (Exception e) {
				try {
					log.error("Row--->"+new String(r.getRow(), "utf-8"), e);
				} catch (UnsupportedEncodingException e1) {
					e1.printStackTrace();
				}
			}
		}
		log.debug(" 将scan转化为planeinfo对象，共用时(ms)："+(System.currentTimeMillis()-start)   +"    转化对象数量："+result.size());
	//	System.out.println("+++++++result.size()+++++++"+result.size());
		return result;
	}

	public static List<HomeChannelCompare> transformHBaseResultToPlaneinfosChannels(
			ResultScanner scan) throws Exception {
		List<HomeChannelCompare> lists = new ArrayList<HomeChannelCompare>();
		for (Result r : scan) {
			HomeChannelCompare com = new HomeChannelCompare();
			/*
			 * PlaneInfos planeInfos = new PlaneInfos(); ChannelPlaneinfo
			 * channelPlaneInfos = new ChannelPlaneinfo();
			 */
			for (KeyValue kv : r.raw()) {
				if ("content".equals(new String(kv.getFamily(), "utf-8"))) {
					// 创建planeInfo对象
					String property = new String(kv.getQualifier(), "utf-8");
					try {
						Method method = com.getClass().getMethod(
								"set" + property.substring(0, 1).toUpperCase()
										+ property.substring(1), String.class);
						method.invoke(com, new String(kv.getValue(), "utf-8"));
					} catch (Exception ex) {
						ex.printStackTrace();
					}
				}

				// 组建channelPlaneinfo对象
				/*
				 * if ("channelPlaneinfo".equals(new String(kv.getFamily(),
				 * "utf-8"))) { // 创建planeInfo对象 String property = new
				 * String(kv.getQualifier(), "utf-8"); try { Method method =
				 * channelPlaneInfos.getClass().getMethod( "set" +
				 * property.substring(0, 1) .toUpperCase() +
				 * property.substring(1), String.class);
				 * method.invoke(channelPlaneInfos, new String(kv.getValue(),
				 * "utf-8")); } catch (Exception ex) { ex.printStackTrace(); } }
				 */
			}
			lists.add(com);
		}
		return lists;
	}

	public static Map<String, Integer> getSpreadsthanBySeRowKey(
			ResultScanner scan, String rowkey) throws Exception {
		Map<String, Integer> map = new HashMap<String, Integer>();
		int count = 0;
		for (Result r : scan) {
			for (KeyValue kv : r.raw()) {
				String threshold = new String(kv.getQualifier(), "utf-8");
				count = Integer.parseInt(new String(kv.getValue(), "utf-8"));
				map.put(new String(r.getRow()) + threshold, count);
			}
		}
		return map;
	}
	
	public static List<TaobaoPriceRubikVO> transformHBaseResultToTaobaoPriceRubikVOs(ResultScanner scan) throws Exception{
		long start = System.currentTimeMillis();	
		Calendar cal=Calendar.getInstance();
//	    cal.add(Calendar.DATE,-1);//当前日期减一天，也就是昨天
	    Date nowadays=new Date();
//	    Date nowadays=cal.getTime();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String s=sdf.format(nowadays)+"000000000";
//		Long  LgTime=Long.valueOf(s).intValue();
		Long LgTime = Long.parseLong(s);  
		List<TaobaoPriceRubikVO> result = new ArrayList<TaobaoPriceRubikVO>();
		List<TaobaoPriceRubikVO> result_2 = new ArrayList<TaobaoPriceRubikVO>();
//		List<PlaneInfo> result = new ArrayList<PlaneInfo>();
		String qualifier,value,family;
		String[] agentInfoKey;
		List<PlaneInfo> getNOagentDatas=new ArrayList<PlaneInfo>();
		TaobaoPriceRubikVO tabaoInfo_2 = new TaobaoPriceRubikVO();//存储直营店信息
		TaobaoPriceRubikVO tabaoInfo_3 = new TaobaoPriceRubikVO();//存储非直营店信息
		for (Result r : scan) {
			List<AgentEntityVO> agents = new ArrayList<AgentEntityVO>();
			Map<String,AgentEntityVO> agentMap = new HashMap<String, AgentEntityVO>();
			TaobaoPriceRubikVO tabaoInfo = new TaobaoPriceRubikVO();
			
			PlaneInfo planeInfo = new PlaneInfo();
			try {
				int k=0;
				String rubikPlace=null;
				String numberZ =null;
				for (KeyValue kv : r.raw()) {
					k++;
					qualifier = new String(kv.getQualifier(),"utf-8");
					family = new String(kv.getFamily(),"utf-8");
					value = new String(kv.getValue(), "utf-8");
					if ("planeinfo".equals(family)) {
						Method method = planeInfoMethods.get("set" + qualifier.substring(0, 1).toUpperCase()+ qualifier.substring(1));
						if(null != method){
							try{
								method.invoke(planeInfo, value);
							}catch(Exception e){log.error(e.getMessage());}
						}
					//	System.out.println("第"+k+"次"+"  qualifier="+qualifier+"  family="+family+"  value="+value);
					}else if ("agentInfos".equals(family)) {
						agentInfoKey = new String(kv.getQualifier(),"utf-8").split("_");
						String property = agentInfoKey[0];
						String str = agentInfoKey[1];
						Method method = agentMethodss.get("set"+ property.substring(0, 1)
								.toUpperCase()+ property.substring(1));
					//	System.out.println("第"+k+"次"+"  qualifier="+qualifier+"  family="+family+"  value="+value);
						if(value.equals("0")){//直营店
							String []zhi=qualifier.split("_");
							numberZ=zhi[1];
						}
						if(qualifier.split("_")[0].equals("name") && qualifier.split("_")[1].equals(numberZ)){
							rubikPlace=value;
						}
						if (null != method) {
							if (!agentMap.containsKey(str)) {
								agentMap.put(str, new AgentEntityVO());
							}
							if (agentMap.keySet().contains(str)) 
								try{
									method.invoke(agentMap.get(str),new String(kv.getValue(), "utf-8"));
								}catch(Exception e){log.error(e.getMessage());}
						}
					}
				}
				//处理得到【代理商】最低价
				agents.addAll(agentMap.values());
				planeInfo.setAgentVO(agents);
				getNOagentDatas.add(planeInfo);//把所有的查询出来的数据保存起来，如果没有直营店时，再拿出来使用
				double getLoerPrice=0.0;
				int falg=0;//用于判断是否存在直营店
				if(agents.size()>0){
				//	System.out.println(" 直营店名字="+rubikPlace);
					for(int w=0;w<agents.size();w++){//这是直营店
						if(agents.get(w).getName().equals(rubikPlace) && (Double.parseDouble(agents.get(w).getPrice()))>0 ){//存在直营店
							getLoerPrice=Double.parseDouble(agents.get(w).getPrice());//直营店的价格
							falg++;//存在直营店
							break;
						}
					}
				}
				
				Long  planInfoGrabdate=Long.parseLong(planeInfo.getGrabDate());
				if(LgTime< planInfoGrabdate && getLoerPrice>0.0 && falg>0){//处理直营店
					tabaoInfo.setAgentLowerPrice(getLoerPrice+"");
				//	tabaoInfo.setAgents(planeInfo.getAgents());
					tabaoInfo.setCarrierKey(planeInfo.getCarrierKey());
					tabaoInfo.setCarrierName(planeInfo.getCarrierName());
					tabaoInfo.setFlightId(planeInfo.getFlightId());
					tabaoInfo.setFromCity(planeInfo.getFromCity());
					tabaoInfo.setToCity(planeInfo.getToCity());
					tabaoInfo.setLowerPrice(planeInfo.getLowerPrice());
					tabaoInfo.setGrabDate(planeInfo.getGrabDate());
					result.add(tabaoInfo);
				}
				
				//过滤抓取日期，只要今天的数据
				
			//	result.add(tabaoInfo);
			} catch (Exception e) {
				System.out.println("抛出异常！");
				e.printStackTrace();
				try {
					log.error("Row--->"+new String(r.getRow(), "utf-8"), e);
				} catch (UnsupportedEncodingException e1) {
					e1.printStackTrace();
				}
			}
		}
	
		
		double getLoerPrice_2=99999999.0;
		int test_1=0;
		if(result.size()>0){
			String getAgentLowerPrics_2=null;
			for(int m=0;m<result.size();m++){
				getAgentLowerPrics_2=result.get(m).getAgentLowerPrice();
				if(Double.parseDouble(getAgentLowerPrics_2)<getLoerPrice_2 && Double.parseDouble(getAgentLowerPrics_2)>0){//如果旗舰店价格为0时，默认此旗舰店不存在
					getLoerPrice_2=Double.parseDouble(getAgentLowerPrics_2);
					test_1=m;
				}
			}
			
	//	}
		tabaoInfo_2.setAgentLowerPrice(result.get(test_1).getAgentLowerPrice());
		tabaoInfo_2.setLowerPrice(result.get(test_1).getLowerPrice());
		tabaoInfo_2.setCarrierKey(result.get(test_1).getCarrierKey());
		tabaoInfo_2.setFlightId(result.get(test_1).getFlightId());
		//tabaoInfo_2.setAgents(result.get(test_1).getAgents());
		tabaoInfo_2.setFromCity(result.get(test_1).getFromCity());
		tabaoInfo_2.setToCity(result.get(test_1).getToCity());
		tabaoInfo_2.setCarrierName(result.get(test_1).getCarrierName());
		tabaoInfo_2.setGrabDate(result.get(test_1).getGrabDate());
		
		if(tabaoInfo_2.getFlightId().length()>0){
			result_2.add(tabaoInfo_2);
		}
		}
		//**********************************************************
		if(result_2.size()<0 || result_2.size()==0){//没有直营店相关数据，再去考虑处理非直营店数据
			if(getNOagentDatas.size()>0){//存在非直营店数据
				double noAgentPrice=0.0;//存储非直营店,代理商最低价
				double flagNoAgentPrice=99999999.0;
				int isNoAgentInt=0;
				for(int qa=0;qa<getNOagentDatas.size();qa++){
					if(LgTime<Long.parseLong(getNOagentDatas.get(qa).getGrabDate())){//只要今天抓取的数据
						noAgentPrice=Double.parseDouble(getNOagentDatas.get(qa).getLowerPrice());
						if(noAgentPrice<flagNoAgentPrice && noAgentPrice>0){
							flagNoAgentPrice=noAgentPrice;
							isNoAgentInt=qa;
						}
					}
				}
				tabaoInfo_3.setLowerPrice(getNOagentDatas.get(isNoAgentInt).getLowerPrice());
				tabaoInfo_3.setFlightId(getNOagentDatas.get(isNoAgentInt).getFlightId());
				tabaoInfo_3.setGrabDate(getNOagentDatas.get(isNoAgentInt).getGrabDate());
				tabaoInfo_3.setCarrierName(getNOagentDatas.get(isNoAgentInt).getCarrierName());
				tabaoInfo_3.setFromAndCityName(getNOagentDatas.get(isNoAgentInt).getFromCityName());
				tabaoInfo_3.setToCityName(getNOagentDatas.get(isNoAgentInt).getToCityName());
				tabaoInfo_3.setAgentLowerPrice("");
			}
			try{
			if(tabaoInfo_3.getFlightId().length()>0 && tabaoInfo_3.getLowerPrice().length()>0){
				result_2.add(tabaoInfo_3);
			}}catch (Exception e) {
				throw new Exception("taobao数据价格为空,排除此数据");
			}
		}
		//**********************************************************
		
		log.debug(" 将scan转化为planeinfo对象，共用时(ms)："+(System.currentTimeMillis()-start)   +"    转化对象数量："+result.size());
		
		return result_2;
		

}
	//处理微信数据
	public static List<PlaneInfo> weixinHbaseHelper(ResultScanner scan)throws Exception{
		List<String> dataList=new ArrayList<String>();
		List<PlaneInfo> getAllPlanInfoDatas=new ArrayList<PlaneInfo>();
	    
		String qualifier,value,family;
//		HBaseHelper.printResult(scan);
		for (Result r : scan) {
			PlaneInfo planeInfo = new PlaneInfo();
			try{
				for (KeyValue kv : r.raw()) {
					qualifier = new String(kv.getQualifier(),"utf-8");
					family = new String(kv.getFamily(),"utf-8");
					value = new String(kv.getValue(), "utf-8");
					if ("planeinfo".equals(family)) {
						Method method = planeInfoMethods.get("set" + qualifier.substring(0, 1).toUpperCase()+ qualifier.substring(1));
						if(null != method){
							try{
								method.invoke(planeInfo, value);
							}catch(Exception e){
								log.error(e.getMessage());
							}
						}
					}
					
				}
			}catch (Exception e) {
				e.printStackTrace();
			}
			getAllPlanInfoDatas.add(planeInfo);//所有的数据包装在planInfo中
		}
		//System.out.println("++++++1++getAllPlanInfoDatas+++"+getAllPlanInfoDatas.size());
		return getAllPlanInfoDatas;
	}
	
	//weixin最低价
	public static String lowererPrice(ResultScanner scan) throws Exception{
		List<PlaneInfo> getAllPlanInfoDatas=new ArrayList<PlaneInfo>();
		getAllPlanInfoDatas=weixinHbaseHelper(scan);
		Date nowadays=new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss");
		String s=sdf.format(nowadays)+"000000000";
		String s2=sdf2.format(nowadays);
		Long LgTime = Long.parseLong(s);  
		Long LgTime2 = Long.parseLong(s2);  
		//处理所有的数据getAllPlanInfoDatas
		/**
		 * 1.过滤出今天抓取的数据
		 * 2.过滤出抓取渠道中最低价的一条航线
		 * 3.组装成String
		 * */
		Double lowerPrices=9999999999.0;
		int k=0;
		String allDataList=null;
		if(getAllPlanInfoDatas.size()>0){
		for(int i=0;i<getAllPlanInfoDatas.size();i++){
			PlaneInfo planInfs = new PlaneInfo();
			planInfs=getAllPlanInfoDatas.get(i);
			if(Long.parseLong(planInfs.getGrabDate())>= LgTime && Long.parseLong(planInfs.getFlightBatchStartTime()+"000")>LgTime2){
				if(Double.parseDouble(planInfs.getLowerPrice())<lowerPrices  ){
					lowerPrices=Double.parseDouble(planInfs.getLowerPrice());
					k=i;
				}
			}
		}
		
		String lowerPrice=getAllPlanInfoDatas.get(k).getLowerPrice().split("\\.")[0];
		String flightId=getAllPlanInfoDatas.get(k).getFlightId().split("\\|")[0];
		String carrierFullName=getAllPlanInfoDatas.get(k).getCarrierFullName();//grabChannel
		String flightStartTime=getAllPlanInfoDatas.get(k).getFlightBatchStartTime().substring(0, 12);
		//String flightStartTimeStr=flightStartTime.substring(0, 4)+"-"+flightStartTime.substring(4, 6)+"-"+flightStartTime.substring(6,8)+" "+flightStartTime.substring(8, 10)+":"+flightStartTime.substring(10, 12);
		String flightStartTimeStr=flightStartTime.substring(8, 10)+":"+flightStartTime.substring(10, 12);
		String grabChannel=getAllPlanInfoDatas.get(k).getGrabChannel();
		allDataList=carrierFullName+","+flightStartTimeStr+","+flightId+","+lowerPrice+","+grabChannel;
		
		}
		return allDataList;
	}
	
	////weixin出行计划
	public static List<String> flightPlane(ResultScanner scan) throws Exception{
		List<PlaneInfo> getAllPlanInfoDatas=new ArrayList<PlaneInfo>();
		List<PlaneInfo> allFlightNu=new ArrayList<PlaneInfo>();
		getAllPlanInfoDatas=weixinHbaseHelper(scan);
		Date nowadays=new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss");
		String s=sdf.format(nowadays)+"000000000";
		String s2=sdf2.format(nowadays);
		Long LgTime = Long.parseLong(s);  
		Long LgTime2 = Long.parseLong(s2);
		List<String> allDataList=new ArrayList<String>();
		//System.out.println("++++++++++=getAllPlanInfoDatas.size()++++="+getAllPlanInfoDatas.size());
		if(getAllPlanInfoDatas.size()>0){//查询出来的数据不为空
			for(int i=0;i<getAllPlanInfoDatas.size();i++){
				PlaneInfo planInfs = new PlaneInfo();
				planInfs=getAllPlanInfoDatas.get(i);
				if(Long.parseLong(planInfs.getGrabDate())>= LgTime && Long.parseLong(planInfs.getFlightBatchStartTime()+"000")>LgTime2){
					allFlightNu.add(planInfs);					
				}
			}
		}
		if(allFlightNu.size()>0){
			for(int k=0;k<allFlightNu.size();k++){
				String lowerPrice=getAllPlanInfoDatas.get(k).getLowerPrice().split("\\.")[0];
				String flightId=getAllPlanInfoDatas.get(k).getFlightId().split("\\|")[0];
				String carrierFullName=getAllPlanInfoDatas.get(k).getCarrierFullName();//grabChannel
				String flightStartTime=getAllPlanInfoDatas.get(k).getFlightBatchStartTime().substring(0, 12);
				//String flightStartTimeStr=flightStartTime.substring(0, 4)+"-"+flightStartTime.substring(4, 6)+"-"+flightStartTime.substring(6,8)+" "+flightStartTime.substring(8, 10)+":"+flightStartTime.substring(10, 12);
				String flightStartTimeStr=flightStartTime.substring(8, 10)+":"+flightStartTime.substring(10, 12);
				String grabChannel=getAllPlanInfoDatas.get(k).getGrabChannel();
				String flighInfo=carrierFullName+","+flightStartTimeStr+","+flightId+","+lowerPrice+","+grabChannel;
				allDataList.add(flighInfo);
			}
			
		}
		//System.out.println("++++++++++++++++returnPlanSize++++++++++++++++++"+allDataList.size());
		return allDataList;
	}
	
}
